package com.woniu.common.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 杜梅杰
 * @description
 * @date 2024/3/14 14:57
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseData<T> {
    private Integer code;
    private String msg;
    private T data;

    //系统用的常量,不要在业务代码中出现
    public ResponseData ok(){
        return new ResponseData(ResponseEnum.SUCCESS.getCode(),
                ResponseEnum.SUCCESS.getMsg(), null);
    }

    public ResponseData ok(T data){
        return new ResponseData(ResponseEnum.SUCCESS.getCode(),
                ResponseEnum.SUCCESS.getMsg(), data);
    }

    public ResponseData ok(T data,String msg){
        return new ResponseData(ResponseEnum.SUCCESS.getCode(), msg, data);
    }

    public ResponseData fail(T data){
        return new ResponseData(ResponseEnum.FAIL.getCode(),
                ResponseEnum.FAIL.getMsg(), data);
    }

    public ResponseData fail(ResponseEnum responseEnum){
        return new ResponseData(responseEnum.getCode(),responseEnum.getMsg(),null);
    }
}
